package org.dfl.plugin.editor.model;

import java.util.ArrayList;
import java.util.Collection;

import org.dfl.core.model.InputPlace;
import org.dfl.core.model.Place;
import org.dfl.core.model.XMLLoaderException;
import org.dfl.messages.Messages;
import org.dfl.plugin.editor.markers.ModelMarkersContainer;
import org.dfl.plugin.editor.markers.ModelProblem;
import org.jdom.Element;


/**
 * editor's model element that represents an input place
 * @author Piotr Wlodarczyk
 *
 */
@SuppressWarnings("serial")
public class InputPlaceModelElement extends PlaceModelElement {
	public InputPlaceModelElement(){
		super();
	}
	
	public InputPlaceModelElement(Element elem) throws XMLLoaderException {
		super(elem);
	}

	@Override
	protected void addTargetConnection(ConnectionModelElement conn) throws Exception{
		throw new Exception(Messages.InputPlaceModelElement_problemInputs);
	}
	
	@Override
	protected Place getDefaultPlace() {
		return new InputPlace();
	}
	
	@Override
	public String getLabelText() {
		return Messages.InputPlaceModelElement_prefix+super.getLabelText();
	}
	
	@Override
	public Collection<ModelProblem> getProblems() {
		Collection<ModelProblem> problems = new ArrayList<ModelProblem>();
		
		if(getPlace().getOutputEdges().isEmpty()){
			problems.add(ModelMarkersContainer.createError(Messages.InputPlaceModelElement_problemNoOutputs ,Messages.InputPlaceModelElement_name, getPlace().getId()));
		}
				
		return problems;
	}
	
	public boolean isConnected(){
		return !getPlace().getOutputEdges().isEmpty();
	}
}
